<template>
  <Card title="查看详情">
    <PriceSupervisionForm :dataSource="dataSource" type="temp" readonly />
    <div class="actions">
      <el-button @click="handleBack()">返回上一层</el-button>
    </div>
  </Card>
</template>
<script>
import {
  getSupervisionTempPriceItemService
} from '@/api/supplier/supervision/approval';
import {
  getTempPriceItem
} from '@/api/supplier/supervision/tempPrice';
import ManageArea from '@/mixins/supplier/manageArea';
import PriceSupervisionForm from '@/pages/supplier/components/priceSupervisionForm'

export default {
  mixins: [ManageArea],
  components: { PriceSupervisionForm },
  data () {
    const { id = 0, processId = 0 } = this.$route.query
    return {
      id,
      processId,
      inited: false,
      dataSource: null,
    }
  },
  created () {
    if (this.processId) {
      this.getPriceItemByProcessId()
    } else if (this.id) {
      this.getPriceItem()
    } else {
      this.handleBack()
    }
  },
  methods: {
    async getPriceItemByProcessId () {
      const resp = await getSupervisionTempPriceItemService({ id: this.processId })
      console.log('resp', resp)
      if (resp && resp.result) {
        this.dataSource = resp.result
      }
      this.inited = true
    },
    // 获取详情数据
    async getPriceItem () {
      const resp = await getTempPriceItem({ id: this.id })
      console.log('resp', resp)
      if (resp && resp.result) {
        this.dataSource = resp.result
      }
      this.inited = true
    },
    handleBack () {
      this.$router.go(-1)
    },
  }
}
</script>
